#ifndef __TREE_ALGORITHMS_H__
#define __TREE_ALGORITHMS_H__

#include "dynamic-tree.h"
#include <vector>
#include <iostream>
#include <cstdarg>

using namespace std;

namespace Trees
{

	class DotPrinter
	{
	public:
		virtual void printDot(ostream& out, const char* fmt, ...) = 0;
	};

	template <class E>
	class Edge
	{
	public:
		Edge(int v1, int v2, const E& value);
		Edge();

		int m_v1;
		int m_v2;
		E m_value;
		
		template <class E1>
		friend istream& operator>>(istream &in, Edge<E1> &edge);
	};
	
	template <class E>
	class Forest : public DotPrinter
	{
	public:
		Forest(const size_t n_ver);
		~Forest();
		
		virtual DynamicTree<int, EdgeInfo<E> >* CreateTree(int value);
		virtual void printDot(ostream& out, const char* fmt, ...) {}
		
		virtual const E MinEdge() const;

		const E MinSpanningTreeMargin(vector<Edge<E> > edges);
		
		size_t n_vertices;
		Trees::DynamicTree<int, EdgeInfo<E> >** m_trees;

	private:
		void InitForest();
		void DeleteForest();
		
	};
	
	template <class E>
	class PathForest : public Forest<E>
	{
	public:
		PathForest(const size_t n_ver);
		
		virtual DynamicTree<int,EdgeInfo<E> >* CreateTree(int value);
		virtual void printDot(ostream& out, const char* fmt, ...);
	
	private:
		int dotCount;
	};

}

#endif
